package cloud.lysky.order.controller;

import cloud.lysky.order.domain.Order;
import cloud.lysky.order.properties.OrderProperties;
import cloud.lysky.order.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RefreshScope
@RestController
@RequestMapping("/api/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class OrderController {

    private final IOrderService orderService;
    private final OrderProperties orderProperties;

    @GetMapping("/create")
    public Order createOrder(@RequestParam Long userId, @RequestParam Long productId) {
        return orderService.createOrder(userId,productId);
    }

    @GetMapping("/config")
    public String getOrderAutoConfirm(){
       return "timeout = " + orderProperties.getTimeout()  + ", autoConfirm = " + orderProperties.getAutoConfirm() + ", dbUrl=" + orderProperties.getDbUrl() ;
    }

    @GetMapping("/funny")
    public String fetchFunnyJoke()  {
        return orderService.fetchFunnyJoke();
    }
}
